<?php
require_once '../sub/init.php';
if(!is_mobile())header("Location: ".Href('my_hongniang'));
$currfields = 'grade,admid,crm_qxnum,crm_yjnum';
require_once ZEAI.'m/my_chk_u.php';
require_once ZEAI.'cache/config_vip.php';
require_once ZEAI.'cache/config_crm.php';
if($t!='hn' && $t!='qx' && $t!='yj')$t='hn';$f=intval($f);
$cook_grade = intval($row['grade']);
$cook_admid = intval($row['admid']);
$cook_crm_qxnum = intval($row['crm_qxnum']);
$cook_crm_yjnum = intval($row['crm_yjnum']);
$nodatatips="<div class='nodatatips'><i class='ico'>&#xe608;</i>暂无牵线约见记录～～</div>";
function rows_ulist($rows,$p) {
	global $_ZEAI,$t,$db,$_CRM;
	$meet_flagARR = json_decode($_CRM['meet_flag'],true);
	$qxflagARR    = json_decode($_CRM['qxflag'],true);
	$uid   = $rows['uid'];
	$admid = $rows['admid'];
	$admname = dataIO($rows['admname'],'out');
	$addtime = YmdHis($rows['addtime'],'Ymd');
	$flag     = $rows['flag'];
	$flagT    = ($t=='yj')?crm_arr_title($meet_flagARR,$flag):crm_arr_title($qxflagARR,$flag);
	//senduid
	$senduid = $rows['senduid'];
	$sendnickname = trimhtml(dataIO($rows['nickname'],'out'));
	$sex     = $rows['sex'];
	$grade   = $rows['grade'];
	$photo_s = $rows['photo_s'];
	$photo_f = $rows['photo_f'];
	$photo_ifshow = $rows['photo_ifshow'];
	$uflag        = $rows['uflag'];
	$photo_s_url = photo_s_out('{"smb":"s","sex":"'.$sex.'","photo_s":"'.$photo_s.'","photo_f":"'.$photo_f.'","photo_ifshow":"'.$photo_ifshow.'","uflag":"'.$uflag.'","outkind":"url"}');
	//uid
	$row2 = $db->ROW(__TBL_USER__,"sex,grade,nickname,photo_s,photo_f,photo_ifshow,flag","id=".$uid,"name");
	if ($row2){
		$sex2      = $row2['sex'];
		$grade2    = $row2['grade'];
		$photo_s2  = $row2['photo_s'];
		$photo_f2  = $row2['photo_f'];
		$photo_ifshow2  = $row2['photo_ifshow'];
		$uflag2  = $row2['flag'];
		$nickname2 = trimhtml(dataIO($row2['nickname'],'out'));
		$photo_s_url2 = photo_s_out('{"smb":"s","sex":"'.$sex2.'","photo_s":"'.$photo_s2.'","photo_f":"'.$photo_f2.'","photo_ifshow":"'.$photo_ifshow2.'","uflag":"'.$uflag2.'","outkind":"url"}');
	}
	$O  = '<ul>';
	$O .= '	<li><a href="'.a('{"kind":"u","uid":"'.$senduid.'"}').'"><img src="'.$photo_s_url.'" class="s"><em>'.uicon($sex.$grade).'<font>'.$sendnickname.'</font></em></a></li>';
	$O .= '	<li><h5>'.$addtime.'</h5><i class="ico">&#xe62d;</i><span>'.$flagT.'</span></li>';
	$O .= '	<li><a href="'.a('{"kind":"u","uid":"'.$uid.'"}').'"><img src="'.$photo_s_url2.'" class="s"><em>'.uicon($sex2.$grade2).'<font>'.$nickname2.'</font></em></a></li>';
	$O .= '<div class="clear"></div></ul>';
	return $O;
}
$_ZEAI['pagesize'] = 15;
switch ($t) {
	case 'hn':
		$t_str='我的红娘';
	break;
	case 'qx':
		$t_str='牵线记录';
		if(!empty($f))$SQL=" AND a.flag=$f";
		$qxnum1 = $db->COUNT(__TBL_QIANXIAN__,"flag=2 AND (uid=".$cook_uid." OR senduid=".$cook_uid.")");
		$qxnum2 = $db->COUNT(__TBL_QIANXIAN__,"flag=1 AND (uid=".$cook_uid." OR senduid=".$cook_uid.")");
		$qxnum3 = $db->COUNT(__TBL_QIANXIAN__,"flag=-1 AND (uid=".$cook_uid." OR senduid=".$cook_uid.")");
		$ZEAI_SQL = "a.senduid=b.id AND (a.senduid=".$cook_uid." OR a.uid=".$cook_uid." )".$SQL;
		$ZEAI_SELECT="SELECT a.senduid,a.uid,a.admid,a.admname,a.addtime,a.flag,b.sex,b.grade,b.nickname,b.photo_s,b.photo_f,b.photo_ifshow,b.flag AS uflag FROM ".__TBL_QIANXIAN__." a,".__TBL_USER__." b WHERE ".$ZEAI_SQL." ORDER BY a.id DESC";
		if($submitok=='ZEAI_list'){exit(Zeai_ajax_list_fn($ZEAI_totalP,$p));}
		$rtt=$db->query("SELECT COUNT(*) FROM ".__TBL_QIANXIAN__." a,".__TBL_USER__." b WHERE ".$ZEAI_SQL);
	break;
	case 'yj':
		$t_str='约见记录';
		if(ifint($f))$SQL=" AND a.meet_flag=$f";
		$yjnum1 = $db->COUNT(__TBL_CRM_MATCH__,"meet_flag=3 AND (uid=".$cook_uid." OR uid2=".$cook_uid.")");//完成
		$yjnum2 = $db->COUNT(__TBL_CRM_MATCH__,"meet_flag=1 AND (uid=".$cook_uid." OR uid2=".$cook_uid.")");//进行中
		$yjnum3 = $db->COUNT(__TBL_CRM_MATCH__,"meet_flag=2 AND (uid=".$cook_uid." OR uid2=".$cook_uid.")");//暂停
		$ZEAI_SQL = "a.uid2=b.id AND (a.uid2=".$cook_uid." OR a.uid=".$cook_uid." )".$SQL;
		$ZEAI_SELECT="SELECT a.uid2 AS senduid,a.uid,a.admid,a.admname,a.addtime,a.meet_flag AS flag,b.sex,b.grade,b.nickname,b.photo_s,b.photo_f,b.photo_ifshow,b.flag AS uflag FROM ".__TBL_CRM_MATCH__." a,".__TBL_USER__." b WHERE ".$ZEAI_SQL." ORDER BY a.id DESC";
		if($submitok=='ZEAI_list'){exit(Zeai_ajax_list_fn($ZEAI_totalP,$p));}
		$rtt=$db->query("SELECT COUNT(*) FROM ".__TBL_CRM_MATCH__." a,".__TBL_USER__." b WHERE ".$ZEAI_SQL);
	break;
}
if($t=='qx' || $t=='yj'){
	$roww = $db->fetch_array($rtt,'num');
	$ZEAI_total = $roww[0];
	$ZEAI_totalP= ceil($ZEAI_total/$_ZEAI['pagesize']);
}
$kf_tel=dataIO($_ZEAI['kf_tel'],'out');$kf_mob=dataIO($_ZEAI['kf_mob'],'out');
$kf_wxpic_url = UP.dataIO($_ZEAI['kf_wxpic'],'out');
$nav='my';?>
<!doctype html><html><head><meta charset="utf-8">
<title>我的-<?php echo $_ZEAI['siteName'];?></title>
<?php echo HEADMETA; ?>
<link href="<?php echo RES;?>m/css/m.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo HOST;?>/cache/zeaicolor.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo RES;?>m/css/my_hongniang.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/m.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script>var t='<?php echo $t;?>';</script>
<style>
.tabmenu a.ed:after{background-color:<?php echo $_ZEAI['mob_mbcolor'];?>}
header.bgcolor{background-color:<?php echo $_ZEAI['mob_mbcolor'];?>}
#backtop a,.btmKefuBtn{background-color:<?php echo $_ZEAI['mob_mbcolor'];?>}
.my_hn_yes .admid .hnpic b{background-color:rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.8)}
.my_hn_yes .admid em.hnpic{border-color:<?php echo $_ZEAI['mob_mbcolor'];?>}
<?php
if ($_ZEAI['m_mb']==2){
	echo '.tabmenufix{width:70%;max-width:500px;top:1.5rem;margin:auto;left:0;right:0}';
	echo '.my_hn_yes{margin-top:13rem}';
	echo '.my_qxyj_info{margin-top:7rem}';
	$mini_class='top_mini4';
}else{
	echo '.tabmenufix{top:6.7rem}';
	echo '#ZEAI_CN__FORM{padding-top:8.8rem}';
	$mini_title='红娘牵线';
	$mini_class='top_mini4 zeaibg bgcolor yunbox';
}
?>
</style>
</head><body><?php
require_once ZEAI.'m/top_mini.php';
if(@!in_array('hn',$navarr)){echo "<div class='nodatatips'><i class='ico'>&#xe659;</i>红娘服务已关闭</div>";exit;}?>
<div class="tabmenu tabmenu3 tabmenufix">
	<a href="my_hongniang.php?t=hn&jumpurl=<?php echo $jumpurl;?>"<?php echo ($t == 'hn')?' class="ed"':'';?>>我的红娘</a>
	<a href="my_hongniang.php?t=qx&jumpurl=<?php echo $jumpurl;?>"<?php echo ($t == 'qx')?' class="ed"':'';?>>牵线记录</a>
	<a href="my_hongniang.php?t=yj&jumpurl=<?php echo $jumpurl;?>"<?php echo ($t == 'yj')?' class="ed"':'';?>>约见记录</a>
</div>
<?php
if ($t == 'hn'){
	$rowhn = $db->ROW(__TBL_CRM_HN__,"truename,ewm,path_s,agentid,agenttitle,mob","ewm<>'' AND id=".intval($cook_admid),'name');//
	if ($rowhn){
		$hn_truename = dataIO($rowhn['truename'],'out');
		$hn_ewm      = $rowhn['ewm'];
		$path_s      = $rowhn['path_s'];
		$agentid     = $rowhn['agentid'];
		$agenttitle  = trimhtml(dataIO($rowhn['agenttitle'],'out'));
		$path_s_url  = (!empty($path_s))?UP.$path_s:RES.'m/img/hnico.jpg';
		$hn_ewm_url  = UP.$hn_ewm;
		$hn_mob      = trimhtml($rowhn['mob']);
		?>
		<div class="my_hn_yes">
            <div class="admid"><em class="hnpic"><img src="<?php echo $path_s_url;?>" /><b>专属红娘</b></em><font class="zeaicolor"><?php echo $hn_truename;?>，工号：<?php echo $cook_admid;?></font></div>
            <?php if (!empty($agenttitle)){echo '<font class="S14">来自：'.$agenttitle.'</font>';}?>
    		<img src="<?php echo $hn_ewm_url; ?>" class="ewm"><h5 class="C999">长按二维码加红娘微信</h5>
            <br>
			<?php if (!empty($hn_mob)){?><i class="ico zeaicolor">&#xe7c1;</i> <a href="tel:<?php echo $hn_mob;?>" class="zeaicolor"><?php echo $hn_mob;?></a><?php }?>
    	</div>
        <?php if (ifint($agentid)){?><a href="<?php echo a('{"kind":"agent_detail","id":"'.$agentid.'"}');?>" class="W80_ btn size4 zeaibg B yuan" style="display:none">　<i class="ico">&#xe71a;</i> 进入我的门店　</a><?php }?>
		<?php
	}else{?>
    	<div class="my_hn_no">
        	<h4>您暂时还没有专属红娘</h4>
        	<img src="<?php echo $kf_wxpic_url; ?>"><h5 class="C999">长按二维码加客服微信咨询</h5>
			<?php if (!empty($kf_tel)){?>
                <i class="ico ">&#xe7c1;</i> <a href="tel:<?php echo $kf_tel;?>" ><?php echo $kf_tel;?></a>
            <?php }else{?>
                <?php if (!empty($kf_mob)){?><i class="ico">&#xe7c1;</i> <a href="tel:<?php echo $kf_mob;?>"><?php echo $kf_mob;?></a><?php }?>
            <?php }?>
            <br><br><br>
			<a href="<?php echo a('{"kind":"hongniang"}');?>" class="btn size4 zeaibg yuan"><i class="ico">&#xe613;</i> 红娘服务大厅</a>
        </div>
    <?php }?>
    <?php require_once ZEAI.'m/TRnav.php';?>
<?php }elseif($t=='qx' || $t=='yj'){ ?>
	<div class="my_qxyj_info">
    	<?php if ($t == 'qx'){?>
            <a href="my_hongniang.php?t=qx&f=2&jumpurl=<?php echo $jumpurl;?>"><i class="ico success"><em><b><?php echo $qxnum1;?></b>次</em></i><span<?php echo ($f == 2)?' class="zeaicolor"':'';?>>成功了</span></a>
            <a href="my_hongniang.php?t=qx&f=1&jumpurl=<?php echo $jumpurl;?>"><i class="ico doing"><em><b><?php echo $qxnum2;?></b>次</em></i><span<?php echo ($f == 1)?' class="zeaicolor"':'';?>>进行中</span></a>
            <a href="my_hongniang.php?t=qx&f=-1&jumpurl=<?php echo $jumpurl;?>"><i class="ico fail"><em><b><?php echo $qxnum3;?></b>次</em></i><span<?php echo ($f == -1)?' class="zeaicolor"':'';?>>失败了</span></a>
        <?php }else{ ?>
            <a href="my_hongniang.php?t=yj&f=3&jumpurl=<?php echo $jumpurl;?>"><i class="ico success"><em><b><?php echo $yjnum1;?></b>次</em></i><span<?php echo ($f == 3)?' class="zeaicolor"':'';?>>已完成</span></a>
            <a href="my_hongniang.php?t=yj&f=1&jumpurl=<?php echo $jumpurl;?>"><i class="ico doing"><em><b><?php echo $yjnum2;?></b>次</em></i><span<?php echo ($f == 1)?' class="zeaicolor"':'';?>>进行中</span></a>
            <a href="my_hongniang.php?t=yj&f=2&jumpurl=<?php echo $jumpurl;?>"><i class="ico fail"><em><b><?php echo $yjnum3;?></b>次</em></i><span<?php echo ($f == 2)?' class="zeaicolor"':'';?>>暂停中</span></a>
        <?php }?>
    </div>
    
    <div class="my_hn_qx" id="ZEAI_list"><?php if($ZEAI_totalP>0){echo Zeai_ajax_list_fn($ZEAI_totalP,$p);}else{echo $nodatatips;}?></div>
    <?php if ($ZEAI_total > $_ZEAI['pagesize']){?>
        <script>
        var ZEAI_totalP = parseInt(<?php echo $ZEAI_totalP; ?>),p=2;
        zeaiOnscroll_json={url:'my_hongniang'+zeai.extname,data:{submitok:'ZEAI_list',ZEAI_totalP:ZEAI_totalP,t:'<?php echo $t;?>',f:<?php echo $f;?>}};
        document.body.onscroll = zeaiOnscroll;
        </script>
        <div id="backtop"><a href="#top" id="btmTopBtn"><i class="ico">&#xe60a;</i>顶部</a></div>
    <?php }?>
<?php }
if($_ZEAI['m_mb']==2){
	require_once ZEAI.'m/bottom2.php';
}else{
	require_once ZEAI.'m/TRnav.php';
	require_once ZEAI.'m/bottom.php';
}
?>